From a0f0932969a0ed946fd51c17a942ed23f84dfd0f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 3 Nov 2016 17:00:13 -0700 Subject: [PATCH] Fix regression with path overrides If an override points to a path dependency then that's not locked, so we're missing information for that, but it's already warned about, so no need to worry. --- src/cargo/core/registry.rs | 10 +++-- tests/overrides.rs | 88 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 037b87a8b..a798a49a5 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -291,9 +291,13 @@ impl<'cfg> PackageRegistry<'cfg> { override_summary: &Summary, real_summary: &Summary) -> CargoResult<()> { let real = real_summary.package_id(); - let map = self.locked.get(real.source_id()).chain_error(|| { - human(format!("failed to find lock source of {}", real)) - })?; + // If we don't have a locked variant then things are going quite wrong + // at this point, but we've already emitted a warning, so don't worry + // about it. + let map = match self.locked.get(real.source_id()) { + Some(map) => map, + None => return Ok(()), + }; let list = map.get(real.name()).chain_error(|| { human(format!("failed to find lock name of {}", real)) })?; diff --git a/tests/overrides.rs b/tests/overrides.rs index ba17e0f32..2ba54fbc2 100644 --- a/tests/overrides.rs +++ b/tests/overrides.rs @@ -925,3 +925,91 @@ fn overriding_nonexistent_no_spurious() { [FINISHED] [..] ").with_stdout("")); } + +#[test] +fn override_to_path_dep() { + Package::new("foo", "0.1.0").dep("bar", "0.1").publish(); + Package::new("bar", "0.1.0").publish(); + + let p = project("local") + .file("Cargo.toml", r#" + [package] + name = "local" + version = "0.0.1" + authors = [] + + [dependencies] + foo = "0.1.0" + "#) + .file("src/lib.rs", "") + .file("foo/Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = { path = "bar" } + "#) + .file("foo/src/lib.rs", "") + .file("foo/bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + "#) + .file("foo/bar/src/lib.rs", "") + .file(".cargo/config", r#" + paths = ["foo"] + "#); + + assert_that(p.cargo_process("build"), + execs().with_status(0)); +} + +#[test] +fn replace_to_path_dep() { + Package::new("foo", "0.1.0").dep("bar", "0.1").publish(); + Package::new("bar", "0.1.0").publish(); + + let p = project("local") + .file("Cargo.toml", r#" + [package] + name = "local" + version = "0.0.1" + authors = [] + + [dependencies] + foo = "0.1.0" + + [replace] + "foo:0.1.0" = { path = "foo" } + "#) + .file("src/lib.rs", "extern crate foo;") + .file("foo/Cargo.toml", r#" + [package] + name = "foo" + version = "0.1.0" + authors = [] + + [dependencies] + bar = { path = "bar" } + "#) + .file("foo/src/lib.rs", " + extern crate bar; + + pub fn foo() { + bar::bar(); + } + ") + .file("foo/bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.1.0" + authors = [] + "#) + .file("foo/bar/src/lib.rs", "pub fn bar() {}"); + + assert_that(p.cargo_process("build"), + execs().with_status(0)); +} -- 2.30.2